<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
loop 4
</h1>
<p></p>
<div id="question" class="tmd-base">
<div class="tmd-usual">
What does the following program print?
</div>
<p></p>
<pre class="tmd-code line-numbers">
<code class="language-go">package main

func main() {
	i, s := 9, []int{}
	
	for i = range s {}
	print(i)
	
	for i = 0; i &lt; len(s); i++ {}
	print(i)

	s = append(s, 1, 2, 3, 4, 5)
	
	for i = range s {}
	print(i)
	
	for i = 0; i &lt; len(s); i++ {}
	println(i)
}
</code></pre>
</div>
<p></p>
<div class="tmd-usual">
Choices:
</div>
<p></p>
<input type="radio" id="choiceA" name="choice" class="choice">
<input type="radio" id="choiceB" name="choice" class="choice">
<input type="radio" id="choiceC" name="choice" class="choice">
<input type="radio" id="choiceD" name="choice" class="choice">

<div id="choices">

<ul style="list-style-type:none;">
<li><label for="choiceA">0055</label></li>
<li><label for="choiceB">9055</label></li>
<li><label for="choiceC">9045</label></li>
<li><label for="choiceD">0045</label></li>
</ul>

</div><p></p>
<div id="answer" class="tmd-base">
<div class="tmd-usual">
Answer: 9045
</div>
<p></p>
<div class="tmd-usual">
Run it on <a href="https://go.dev/play/p/muRnQApAInP">Go play</a>.
</div>
<p></p>
<div class="tmd-usual">
Key point:
</div>
<ul class="tmd-list">
<li class="tmd-list-item">
<div class="tmd-usual">
A <code class="tmd-code-span">for-range</code> loop never set the first iteration variable to an invalid index.
</div>
</li>
</ul>
<p></p>
</div>
<p></p>
</div>
